package cn.qingyun.gis.modules.init.system.convert;

import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.excel.converters.string.StringImageConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.util.Base64;

public class CustomizeImageConverter extends StringImageConverter {
    @Override
    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) {

        if (CharSequenceUtil.isNotBlank(value)) {
            value = value.replaceAll("data:image/jpeg;base64,", "");
            return new WriteCellData<>(Base64.getDecoder().decode(value));
        } else {
            return null;
        }
    }

}